package com.mumu.muPictureBackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mumu.muPictureBackend.model.entity.Space;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;

@MapperScan
public interface SpaceMapper extends BaseMapper<Space> {
    // 添加图片后 用于更新空间已用总容量
    @Update("UPDATE space set tatalSize=totalSize+#{picSize},totalCount=totalCount+1 where id=#{spaceId}")
    void updateSpaceSizeAdd(@Param("spaceId") long spaceId, @Param("picSize") long picSize);

    // 删除图片后 用于从用了的总容量中减去该图片的大小
    @Update("UPDATE space set totalSize=totalSize+#{picSize},totalCount=totalCount-1 where spaceId=#{spaceId}")
    void updateSpaceSizeSub(@Param("spaceId") long spaceId, @Param("picSize") long picSize);
}
